//
//  y_HotCarTableViewCell.m
//  CarWorld
//
//  Created by yuyu on 15/3/25.
//  Copyright (c) 2015年 CarWorldTeam. All rights reserved.
//

#import "y_HotCarTableViewCell.h"
#import "NSString+Attributed.h"

@implementation y_HotCarTableViewCell

- (void)dealloc
{
    [_cellData release];
    [_image_View release];
    [_nameLbl release];
    [_priceLbl release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    return [self initWithStyle:style reuseIdentifier:reuseIdentifier height:0];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier height:(CGFloat)height
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        CGRect rect = [UIScreen mainScreen].bounds;
        CGFloat imageViewWidth = (rect.size.width-20)*0.3;
        CGFloat pHeight = height-10;
        _image_View = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, imageViewWidth, pHeight)];
        [self.contentView addSubview:_image_View];
        
        CGFloat Width = rect.size.width - imageViewWidth - 10;
        _nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(10+5+imageViewWidth, 5, Width, (pHeight-5)/2)];
        [self.contentView addSubview:_nameLbl];
        
        _priceLbl = [[UILabel alloc] initWithFrame:CGRectMake(10+5+imageViewWidth, 5 + 5 + (pHeight-5)/2, Width, (pHeight-5)/2)];
        _priceLbl.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_priceLbl];
    }
    return self;
}


- (void)setCellData:(y_HotCarCellData *)cellData
{
    if (_cellData!=cellData) {
        [_cellData release];
        _cellData = [cellData retain];
        _nameLbl.text = cellData.MODEL_NAME;
        _priceLbl.text = [NSString stringWithFormat:@"指导价：%@",cellData.REF_PRICE];
        //_priceLbl.attributedText = [_priceLbl.text tintColor:[UIColor redColor] subString:cellData.REF_PRICE];
        _priceLbl.attributedText = [_priceLbl.text tintSubStringColorWithDictionary:@{@"指导价":[UIColor grayColor],cellData.REF_PRICE:[UIColor redColor]}];
        if (_cellData.image==nil) {
            
        }
        else
        {
            _image_View.image = self.cellData.image;
        }
        
    }
}

// 自绘分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, rect);
    
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0xE2/255.0f green:0xE2/255.0f blue:0xE2/255.0f alpha:1].CGColor);
    CGContextStrokeRect(context, CGRectMake(10, rect.size.height - 1, rect.size.width-30, 1));
}

@end
